home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacsBug / MacsBug 6.1 / dcmds / Contributed dcmds / Drvr.c next >
Encoding:
C/C++ Source or Header  |  1989-04-21  |  4.7 KB  |  224 lines  |  [TEXT/MPS ]

  1. /*     drvr.c
  2.     This is the Unit Table dcmd.
  3.  
  4.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  5.  
  6.     Modification history:
  7.          7Dec88 sad        show driver version
  8.         29Nov88 sad        revised for new dcmd names
  9.         13Oct88 sad        written from file.c
  10.  
  11.     The following MPW commands will build the dcmd and copy it to the
  12.     "Debugger Prefs" file in the System folder. The dcmd's name in
  13.     MacsBug will be the name of the file built by the Linker.
  14.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  15.     C Samples folder into this folder.
  16.  
  17.     C Put.c
  18.     C Drvr.c
  19.     Link dcmdGlue.a.o Drvr.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Drvr
  20.     BuildDcmd Drvr 1000
  21. */
  22.  
  23. #ifdef USESTDIO
  24. #include <stdio.h>
  25. #endif
  26.  
  27. #include <Types.h>
  28. #include <Memory.h>
  29. #include <Devices.h>
  30. #include <SysEqu.h>
  31.  
  32. #include "dcmd.h"
  33. #include "put.h"
  34.  
  35.  
  36. typedef struct DRVR
  37.     {
  38.     short drvrFlags;
  39.     short drvrDelay;
  40.     short drvrEMask;
  41.     short drvrMenu;
  42.     short drvrOpen;
  43.     short drvrPrime;
  44.     short drvrCtl;
  45.     short drvrStatus;
  46.     short drvrClose;
  47.     Str255 drvrName;
  48.     } DRVR;
  49.  
  50.  
  51. static void DrawHdr()
  52. {
  53. //                             1         2         3         4         5         6         7
  54. //                    12345678901234567890123456789012345678901234567890123456789012345678901234567890
  55.     dcmdDrawLine("\pdRef dNum Driver      Flg  Ver qHead Storage Window Dely  Drvr at DCE at");
  56. }
  57.  
  58.  
  59. static void DrawDCE(int dref, AuxDCE* dcep)
  60. {
  61.     DRVR* drvrp;
  62.  
  63.     PutUHexWord(dref);
  64.     PutSpace();
  65.     PutUHexWord(~dref);
  66.     PutSpace();
  67.     if (dcep->dCtlFlags & 0x40)
  68.         {
  69.         drvrp = *(DRVR**)dcep->dCtlDriver;
  70.         if (drvrp) PutPStrTruncTo(drvrp->drvrName,21);
  71.         else PutPStrTruncTo("\p-purged-",21);
  72.         }
  73.     else
  74.         {
  75.         drvrp = (DRVR*)dcep->dCtlDriver;
  76.         PutPStrTruncTo(drvrp->drvrName,21);
  77.         }
  78.     PutSpace();
  79.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  80.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  81.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  82.     PutSpace();
  83.     PutUDecTo((unsigned char)dcep->dCtlQHdr.qFlags,30);
  84.     PutSpace();
  85.     PutUHexZTo((unsigned long)dcep->dCtlQHdr.qHead,6,36);
  86.     PutSpace();
  87.     PutUHexZTo((unsigned long)dcep->dCtlStorage,6,44);
  88.     PutSpace();
  89.     PutUHexZTo((unsigned long)dcep->dCtlWindow,6,51);
  90.     PutSpace();
  91.     PutUHexWord((unsigned long)dcep->dCtlDelay);
  92.     PutSpace();
  93.     PutUHexZTo((unsigned long)drvrp,6,65);
  94.     PutSpace();
  95.     PutUHexZTo((unsigned long)dcep,6,72);
  96.     PutLine();
  97.     if (dref != dcep->dCtlRefNum)
  98.         {
  99.         // this case actually happens normally for drvr fffe .Sony for the HD20 (pre-SCSI)
  100.         PutPStr("\p   that’s strange:  dCtlRefNum = ");
  101.         PutUHexWord(dcep->dCtlRefNum);
  102.         PutLine();
  103.         }
  104. } // DrawDCE
  105.  
  106. // EJECT
  107.  
  108. pascal void CommandEntry(dcmdBlock* paramPtr)
  109. {
  110.     switch (paramPtr->request)
  111.         {
  112.         case dcmdInit:
  113.             break;
  114.  
  115.         case dcmdHelp:
  116.             dcmdDrawLine("\pdrvr [refnum|num]");
  117.             dcmdDrawLine("\p   Displays driver information for the given refnum or all installed drivers.");
  118.             dcmdDrawLine("\p      Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  119.             break;
  120.  
  121.         case dcmdDoIt:
  122.             {
  123.             Boolean doOne = false;
  124.             long dref;
  125.             int numdces;
  126.  
  127.             dcmdSwapWorlds();
  128.  
  129.             dcmdDrawLine("\pDisplaying Driver Control Entries");
  130.  
  131.           // get low-memory values after dcmdSwapWorlds()
  132.             numdces = *(unsigned short *)UnitNtryCnt;
  133.  
  134.             (void)dcmdGetNextExpression(&dref, &doOne);
  135.  
  136.             if (doOne)
  137.                 {
  138.                 int dnum;
  139.                 dref = (short)dref;
  140.                 if (dref < 0) dnum = ~dref;
  141.                 else
  142.                     {
  143.                     dnum = dref;
  144.                     dref = ~dref;
  145.                     }
  146.                 if (dnum > numdces)
  147.                     {
  148. #ifdef USESTDIO
  149.                     Str255 line;
  150.                     sprintf(line,"bad refnum 0x%.4x",(unsigned short)dref);
  151.                     dcmdDrawLine((Str255)c2pstr(&line));
  152. #else
  153.                     PutPStr("\pbad refnum ");
  154.                     PutUHexWord(dref);
  155.                     PutSpace();
  156.                     PutUHexWord(~dref);
  157.                     PutLine();
  158. #endif
  159.                     }
  160.                 else
  161.                     {
  162.                     AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
  163.                     if (dceh)
  164.                         {
  165.                         DrawHdr();
  166.                         DrawDCE(dref,*dceh);
  167.                         }
  168.                     else
  169.                         {
  170.                         PutPStr("\pDriver ");
  171.                         PutUHexWord(dref);
  172.                         PutSpace();
  173.                         PutUHexWord(~dref);
  174.                         PutPStr("\p is not in installed");
  175.                         PutLine();
  176.                         }
  177.                     }
  178.                 }
  179.             else
  180.                 {
  181.                 int dcesused = 0;
  182.                 int dnum;
  183.                 AuxDCE*** dcehp;
  184.                 Boolean foundOne = false;
  185.                 for (dnum = 0, dcehp = *(AuxDCE****)UTableBase;
  186.                      dnum < numdces;
  187.                      dnum++, dcehp++)
  188.                     {
  189.                     if (*dcehp)
  190.                         {
  191.                         dcesused++;
  192.                         if (!foundOne)
  193.                             {
  194.                             DrawHdr();
  195.                             foundOne = true;
  196.                             }
  197.                         DrawDCE(~dnum,**dcehp);
  198.                         }
  199.                     if (paramPtr->aborted) break;
  200.                     }
  201.                 if (!paramPtr->aborted)
  202.                     {
  203.                     PutUDec(numdces);
  204.                     PutPStr("\p Unit Table entries, ");
  205.                     PutUDec(dcesused);
  206.                     PutPStr("\p in use, ");
  207.                     PutUDec(numdces - dcesused);
  208.                     PutPStr("\p free");
  209.                     PutLine();
  210.                     }
  211.                 }    
  212.  
  213.             dcmdSwapWorlds();
  214.             }
  215.             break;
  216.  
  217.         default:
  218.             PutPStr("\punknown request ");
  219.             PutUDec(paramPtr->request);
  220.             PutLine();
  221.             break;
  222.         }
  223. } // CommandEntry
  224.